<?php

include_once('global.php');

/**
 * 指定长度的字符串截取
 * @param type $str
 * @param type $len
 * @return type
 */
function sub($str, $len) {
    $i = 0;
    while ($i < $len) {

        if (ord($str[$i]) > 128) {
            $i = $i + 2;
        }
        $i++;
    }
    return substr($str, 0, $i) . "...";
}

$sql = "SELECT * FROM `p_newsclass` where f_id=0 order by id DESC";
$query = $db->query($sql);
while ($row_class = $db->fetch_array($query)) {
    $sm_class[] = array("name" => $row_class[name], "id" => $row_class[id]);
}


$smarty->assign("sm_class", $sm_class); //杲掚崐
//==============

$sql = "SELECT * FROM p_config";
$query = $db->query($sql);
while ($row_config = $db->fetch_array($query)) {
    $sm_config[] = $row_config[values];
}

$smarty->assign("sm_config", $sm_config); //配置引入
//==============

$sql = "SELECT * FROM `p_newsbase` where cid=29 order by id DESC limit 8";
$query = $db->query($sql);
while ($row_news = $db->fetch_array($query)) {
    $sql = "select `diu_place`,`name`from p_newsbase as a, p_newscontent as b where a.id=b.nid and a.id='$row_news[id]'";
    $query = mysql_query($sql);
    $row_newsweibo = mysql_fetch_array($query);
    if (strlen($row_news[title]) > 27) {
        $row_news[title] = sub($row_news[title], 27);
    }
    if (strlen($row_news[keyword]) > 80) {
        $row_news[keyword] = sub($row_news[keyword], 80);
    }
    $sw_news[] = array("title" => $row_news[title], "id" => $row_news[id], "keyword" => $row_news[keyword], "time" => date("m-d", $row_news[date_time]), "didian" => $row_newsweibo[diu_place], "name" => $row_newsweibo[name]);
}
$smarty->assign("sw_news", $sw_news);

$sql = "SELECT * FROM `p_newsbase` where cid=30 order by id DESC limit 8";
$query = $db->query($sql);
while ($row_news = $db->fetch_array($query)) {
    $sql = "select `diu_place`,`name`from p_newsbase as a, p_newscontent as b where a.id=b.nid and a.id='$row_news[id]'";
    $query = mysql_query($sql);
    $row_newsweibo = mysql_fetch_array($query);
    if (strlen($row_news[title]) > 27) {
        $row_news[title] = sub($row_news[title], 27);
    }
    if (strlen($row_news[keyword]) > 80) {
        $row_news[keyword] = sub($row_news[keyword], 80);
    }
    $zl_news[] = array("title" => $row_news[title], "id" => $row_news[id], "keyword" => $row_news[keyword], "time" => date("m-d", $row_news[date_time]), "name" => $row_newsweibo[name], "didian" => $row_newsweibo[diu_place]);
}
$smarty->assign("zl_news", $zl_news);
//=============


$sql = "select total from  number";
$query = $db->query($sql);
$number = $db->fetch_array($query);
$total = $number['total'] + 1;
$sql = "update `number` SET `total` =  $total WHERE `id` =1 LIMIT 1";
$db->query($sql);
$smarty->assign("number", $number);
$smarty->display("index_test.htm");
?>

